package com.aconcagua.samples.charts.controller.commands {
  import com.aconcagua.samples.charts.controller.gestures.ZoomGesture;
  import com.aconcagua.samples.charts.service.ChartServiceDelegate;
  import com.aconcagua.samples.charts.state.ApplicationState;
  import com.aconcagua.samples.charts.state.model.model;
  
  import mx.collections.ArrayCollection;
  import mx.rpc.events.ResultEvent;
  
  public class ZoomCommand extends ResponderCommand {
    private var _state: ApplicationState;
    private var _service: ChartServiceDelegate;

    public function ZoomCommand(state: ApplicationState, service: ChartServiceDelegate) {
      super(onResult);
      _state = state;
      _service = service;
    }

    public function execute(gesture: ZoomGesture): void {
      var seriesIds: ArrayCollection = new ArrayCollection();

      _state.slider.zoom(gesture.timeFrom, gesture.timeTo);
      _service.getData(gesture.dateFrom, gesture.dateTo).invoke(this);
    }
    
    public function onResult(event: ResultEvent): void {
      _state.model::refreshSeries(event.result as ArrayCollection);
    }
  }
}